package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"hostipal/models"
)

type HospitalController struct {
	beego.Controller
}

type JsonRes struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *HospitalController) List() {
	page, _ := c.GetInt("p", 1)
	pageSize, _ := c.GetInt("s", 5)
	var map1 = make(map[string]interface{})
	sum, hospital, err := models.List(page, pageSize)
	map1["sum"] = sum
	map1["data"] = hospital
	if err != nil {
		c.Data["json"] = JsonRes{
			Code: 500,
			Msg:  "展示失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonRes{
			Code: 200,
			Msg:  "展示成功",
			Data: map1,
		}
		c.ServeJSON()
	}
}
